package com.neusoft.hifly.dynamicds.multi.datasource.dao.impl;

import org.redisson.api.RMap;
import org.redisson.api.RedissonClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import com.neusoft.hifly.dynamicds.multi.datasource.dao.IDatasourceRouterDao;
import com.neusoft.hifly.dynamicds.multi.datasource.domain.DatasourceRouterObj;

@Repository
public class DatasourceRouterDaoImpl implements IDatasourceRouterDao {

	@Autowired(required = false)
	private RedissonClient redisson;

	/**
	 * 通过租户编码查询数据源
	 *
	 * @param organCode
	 *            租户编码
	 * @return 数据源
	 */
	@Override
	public DatasourceRouterObj getByOrganCode(String organCode) {

		// 查询缓存
		RMap<String, DatasourceRouterObj> rset = redisson.getMap(DatasourceRouterObj.REDIS_KEY + ":" + organCode);
		if (rset != null && rset.containsKey(organCode)) {
			// 缓存命中
			return rset.get(organCode);
		}
		return null;
	}

}
